package com.example.student.controller;


import com.example.common.domain.Result;
import com.example.common.domain.pojo.Attendance;
import com.example.student.domain.Dto.SignInDto;
import com.example.student.service.AttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "学生端接口", description = "学生签到")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/students")
@RequiredArgsConstructor
public class SignInController {
    @Autowired
    private AttendanceService attendanceService;

    @ApiOperation("学生签到单个查询")
    @GetMapping("/getAttendance/{studentId}")
    public Result<Attendance> getAttendance(@PathVariable String studentId) {
        return Result.success(attendanceService.StudentgetAttendance(studentId));
    }

    @ApiOperation("学生签到列表查询")
    @GetMapping("/getAttendanceList/{studentId}")
    public Result<List<Attendance>> getAttendanceList(@PathVariable String studentId) {
        return Result.success(attendanceService.getByStudentIds(studentId));
    }

    @ApiOperation("学生签到")
    @GetMapping("/signIn")
    public Result<Attendance> signIn(@RequestBody SignInDto sign) {
        if (attendanceService.IsSignIn(sign.getStudentId(), sign.getSignId(), sign.getCode())) {
            attendanceService.signIn(sign.getStudentId(), sign.getSignId());
            return Result.error("已签到");
        } else return Result.error("签到码错误");
    }


}
